import requests
import json

data = {}
<#list columns as col>
<#if col.type == 'DOUBLE'>
data["${col.name}"] = 1
<#elseif col.type == 'DECIMAL'>
data["${col.name}"] = 1
<#elseif col.type == 'LONG'>
data["${col.name}"] = 1
<#elseif col.type == 'INT'>
data["${col.name}"] = 1
<#elseif col.type == 'FLOAT'>
data["${col.name}"] = 1
<#elseif col.type == 'TIMESTAMP'>
# 设置日期时间类型为yyyy-MM-dd格式的字符类型
data["${col.name}"] = '2018-01-01'
<#elseif col.type == 'DATETIME'>
# 设置日期时间类型为yyyy-MM-dd格式的字符类型
data["${col.name}"] = '2018-01-01'
<#else>
data["${col.name}"] = 'label'
</#if>
</#list>

# header中传递App-Key和App-Token，其中App-Token是使用AppSecret和Public Key(公钥)进行RSA加密产生
headers = {};
<#if token ??>
# 传递流程参数，调用时可以更改参数值，也可以不传递参数，将使用默认值
# 例如，参数名为table，值为t_movies_ratings, 则参数传递为：
# flowParamsSync1['table'] = 't_movies_ratings';
flowParamsSync1 = {};
flowParamsSync2 = {};
<#list service1Params as param>
<#if param.paramName != '' && param.paramName != 'system.appId' && param.paramType != 'datasource'>
flowParamsSync1['${param.paramName}'] = '${param.paramValue}'
</#if>
</#list>
<#list service2Params as param>
<#if param.paramName != '' && param.paramName != 'system.appId' && param.paramType != 'datasource'>
flowParamsSync2['${param.paramName}'] = '${param.paramValue}'
</#if>
</#list>
request = {
    "data": [data],
    "flowParamsSync1": flowParamsSync1,
    "flowParamsSync2": flowParamsSync2
};

headers["App-Key"] = "${token.key!''}";
headers["App-Token"] = "RSA(AppSecret + '-' + new Date().getTime(), Public Key)";
# 获取App-Token
getTokenUrl = '${urlPrefix}/api/ai/platform/service/gen-token'
tokenParams = {'text': '${token.secret!''}'}
resDict = requests.post(getTokenUrl, params=tokenParams, verify=False)
contentDict = json.loads(str(resDict.content, encoding='utf8'))
headers["App-Token"] = contentDict['data']
headers["Content-Type"] = "application/json;charset=UTF-8"
</#if>

grayUrl = '${urlPrefix}/ai/webapi/model/gray/${service.serviceAddr}'
res = requests.post(grayUrl,headers = headers,data = json.dumps(request), verify=False)

grayResult = json.loads(str(res.content, encoding='utf8'))
print(res.text)